package utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class JsonUtils {
   // 创建ObjectMapper对象
   private static ObjectMapper objectMapper = new ObjectMapper();

   // 将Java对象转换为JSON字符串并输出
   public static String objectToString(Object o) throws JsonProcessingException {
      return objectMapper.writeValueAsString(o);
   }

   public static <T> T stringToObject(String jsonString, Class<T> clazz) throws JsonProcessingException {
      return objectMapper.readValue(jsonString, clazz);
   }
}
